<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var maxSubArray = function (nums) {
        let sum = 0
        let res = -Infinity
        for (let i = 0; i < nums.length; i++) {
          if (sum >= 0) {
            sum += nums[i]
          } else {
            sum = nums[i]
          }
          res = Math.max(res, sum)
        }
        return res
      }
    </script>
  </body>
</html>
